<template>
	<view class="index">


		<Banner :detail="banner" v-if="banner.length > 0" @getbgcolor="getbgcolor"></Banner>
		<uni-notice-bar scrollable="true" @click="goRoll(singNew)" single="true" :speed="10" showIcon="true" :text="singNew.info"></uni-notice-bar>
		 
		
		<uni-section :title="printStore" type="line" @click="select"></uni-section>
			
		<btnCard color="#adc0f9" img="../static/img/doc.png" :title="'文档&图片打印'" :desc="'支持word/ppt/pdf/excel/图文等文件打印'" @tap="goUpload"></btnCard>
		<btnCard color="#bbffcb" img="../static/img/idcard.png" :title="'证件复印'" :desc="'身份证/户口本'" @tap="getclass"></btnCard>

		
		</view>
</template>
<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import GoodList from '@/components/GoodList';
import btnCard from '@/components/btnCard.vue';
import PromotionGood from '@/components/PromotionGood';
import CouponWindow from '@/components/CouponWindow';

import UniNoticeBar from '@/components/uni-notice-bar/uni-notice-bar';
import Adv from '@/components/sh-adv';
import Groupon from '@/components/sh-groupon.vue';
//
import { wxappAuth, getUser, getUserInfo } from '@/api/user';
//
import Banner from './components/Banner';
import HotCommodity from './components/HotCommodity';
import FirstNewProduct from './components/FirstNewProduct';
import SeckillProduct from './components/SeckillProduct';
import SeckillSeckill from './components/SeckillSeckill';
// import ProductsRecommended from "./components/ProductsRecommended";
import Recommend from '@/components/Recommend';
import store from '@/store';

// import Live from "./components/Live";

import { getHomeData, getShare } from '@/api/public';
import cookie from '@/utils/store/cookie';
import { isWeixin, handleUrlParam } from '@/utils/index';
import { getSeckillConfig, getSeckillList } from '@/api/activity';
//
import { openShareAll } from '@/libs/wechat';

const HAS_COUPON_WINDOW = 'has_coupon_window';

export default {
	name: 'Index',
	components: {
		btnCard,
		// swiper,
		// swiperSlide,
		UniNoticeBar,
		GoodList,
		PromotionGood,
		CouponWindow,

		Adv,
		Groupon,
		Banner,
		HotCommodity,
		FirstNewProduct,
		//ProductsRecommended,
		Recommend,
		SeckillProduct,
		SeckillSeckill
		// Live,
	},
	props: {},
	data: function() {
		return {
			printStore:cookie.get("print")?cookie.get("print"):"请点击选择打印店",
			avatar1: 'https://img.88icon.com/upload/jpg/20210524/ff06f47790f5dbc90300dda28f032474_31334_716_819.jpg!bg',
			avatar2: 'https://gd-hbimg.huaban.com/7211ef2f0c917c380c784e0406e73b3795cdb6a819dc2-P8C8SG_fw658',
			statusBarHeight: 0,
			titleBarHeight: 0,
			heiOuat:0,
			tipContent: '',
			CustomBar: this.CustomBar,
			StatusBar: this.StatusBar,
			formatMenus: [],
			categoryCurrent: 0,
			menuNum: 4,
			/*#ifdef MP-WEIXIN*/
			bgcolor: '#ffffff',
			/*#endif*/
			/* #ifdef H5 */
			/*#endif*/

			bgColor: '#ffffff',
			swiperCurrent: 0, //轮播下标
			webviewId: 0,
			showCoupon: false,
			logoUrl: '',
			banner: [],
			menus: [],
			combinationList: [],
			combinationListB: [],
			roll: [],
			activity: [],
			activityOne: {},
			bastList: [],
			firstList: [],
			info: {
				fastList: [],
				bastBanner: [],

				bastList: []
			},
			likeInfo: [],
			live: [],
			lovely: [],
			benefit: [],
			couponList: [],
			seckillList: [{}],
			seckItem: [],
			swiperOption: {
				pagination: {
					el: '.swiper-pagination',
					clickable: true
				},
				autoplay: {
					disableOnInteraction: false,
					delay: 2000
				},
				loop: true,
				speed: 1000,
				observer: true,
				observeParents: true
			},
			swiperRoll: {
				direction: 'vertical',
				autoplay: {
					disableOnInteraction: false,
					delay: 2000
				},
				loop: true,
				speed: 1000,
				observer: true,
				observeParents: true
			},
			swiperScroll: {
				freeMode: true,
				freeModeMomentum: false,
				slidesPerView: 'auto',
				observer: true,
				observeParents: true
			},
			swiperBoutique: {
				pagination: {
					el: '.swiper-pagination',
					clickable: true
				},
				autoplay: {
					disableOnInteraction: false,
					delay: 2000
				},
				loop: true,
				speed: 1000,
				observer: true,
				observeParents: true
			},
			swiperProducts: {
				freeMode: true,
				freeModeMomentum: false,
				slidesPerView: 'auto',
				observer: true,
				observeParents: true
			},
			bgImage: ''
		};
	},
	computed: {
		singNew() {
			if (this.roll != null) {
				return this.roll.length > 0 ? this.roll[0] : '你还没添加通知哦！';
			}
		},
		customStyle() {
			var bgImage = this.bgImage;
			// var style = `height:${this.CustomBar}px;padding-top:${0}px;background: ${this.bgcolor}`;
			var style = `height:${this.CustomBar}px;padding-top:${this.StatusBar}px;background: ${this.bgcolor}`;
			if (this.bgImage) {
				style = `${style}background-image:url(${bgImage});`;
			}
			return style;
		}
	},	
	onLoad: function() {
		
		let menuButtonObject = uni.getMenuButtonBoundingClientRect(); //获取菜单按钮（右上角胶囊按钮）的布局位置信息。坐标信息以屏幕左上角为原点。
		uni.getSystemInfo({ //获取系统信息
			success: res => {
				let navHeight = menuButtonObject.height + (menuButtonObject.top - res.statusBarHeight) *
				2; //导航栏高度=菜单按钮高度+（菜单按钮与顶部距离-状态栏高度）*2
				// 导航栏（胶囊）高度
				this.titleBarHeight = navHeight;
				//  状态栏（顶部）高度
				this.statusBarHeight = res.statusBarHeight
				this.heiOuat = this.statusBarHeight+this.titleBarHeight+5
				console.log(this.titleBarHeight);
				console.log(this.statusBarHeight);
			},
			fail(err) {
				console.log(err);
			}
		})
			
		// let systemInfo = uni.getSystemInfoSync();
		// this.statusBarHeight = systemInfo.statusBarHeight;
		// let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
		// this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height;
		// console.log('22222222',this.menuButtonInfo)
		// this.heiOuat = this.statusBarHeight+this.titleBarHeight+20
		this.getLocation();

		let that = this;
		uni.showLoading({
			title: '加载中'
		});

		getHomeData().then(res => {
			let arrList = new Array();
			that.logoUrl = res.data.logoUrl;
			res.data.banner.map(item => (item.bgcolor = item.color || ''));
			res.data.banner.map(item => {
				arrList.push(item);
				// if (item.position == 4) {
				// 	arrList.push(item);
				// }
			});
			that.$set(that, 'banner', arrList);
			that.$set(that, 'menus', res.data.menus);
			that.$set(that, 'roll', res.data.roll);
			//  that.$set(that, "info", res.data.info);
			that.$set(that, 'firstList', res.data.firstList);
			that.$set(that, 'bastList', res.data.bastList);
			that.$set(that, 'likeInfo', res.data.likeInfo);
			// that.$set(that, "live", res.data.liveList);
			// that.$set(that, "lovely", res.data.lovely);
			// that.$set(that, "benefit", res.data.benefit);
			that.$set(that, 'couponList', res.data.couponList);
			// that.$set(that, "combinationList", res.data.combinationList);

			//   that.$set(that, "combinationList", res.data.cateProductList[1].cateProductList);
			// console.log('2222',that.combinationList)
			// console.log(res);
			uni.hideLoading();
			that.setOpenShare();
			// that.doColorThief()
			// that.mountedStart();
		});
		var storageUid = uni.getStorageSync('uid');

		// console.log("ccccc", arr);

		if (storageUid) {
			getUserInfo().then(user => {
				console.log('获取用户信息成功');
				uni.setStorageSync('uid', user.data.uid);
				if (!user.data.levelName) {
					this.tipContent = '进行身份认证后，可享受平台商品的特有优惠';
					this.$refs.popup.open();
				}
			});
		}
	},
	methods: {
		goUpload(){
			if(!cookie.get("print") || cookie.get("print")==''){
				uni.showToast({
					title: '请先选择打印机',
					icon: 'none'
				})
				return
			}
			this.$yrouter.push('/pages/shop/ShoppingCart/index');
		},
		select(){
			this.$yrouter.push('/pages/home/printList/printList');
		},
		goFestival() {
			this.$yrouter.push('/pages/festivaIActivity/festivaIActivity');
		},
		goAssist() {
			this.$yrouter.push('/pages/assist/assist');
		},
		getclass() {
			if(!cookie.get("print") || cookie.get("print")==''){
				uni.showToast({
					title: '请先选择打印机',
					icon: 'none'
				})
				return
			}
			this.$yrouter.push('/pages/shop/idcard/idcard');
		},
		...mapActions(['getLocation']),

		onShareTimeline: function() {
			return {
				title: this.miniHomeRemark,
				imageUrl: this.miniHomeImg,
				path: 'pages/home/index?spread=' + uni.getStorageSync('uid')
			};
		},
		onShareAppMessage: function() {
			return {
				title: this.miniHomeRemark,
				imageUrl: this.miniHomeImg,
				path: 'pages/home/index?spread=' + uni.getStorageSync('uid')
			};
		},
		goRoll(item) {
			if (item.uniapp_url) {
				this.$yrouter.push(item.uniapp_url);
			}
		},

		goGoodSearch() {
			// this.$yrouter.push('/pages/shop/GoodsEvaluate/index');
			this.$yrouter.push('/pages/shop/GoodSearch/index');
		},
		goWxappUrl(item) {
			this.$yrouter.push(item.uniapp_url);
		},
		goHotNewGoods(type) {
			this.$yrouter.push({
				path: '/pages/shop/HotNewGoods/index',
				query: {
					type
				}
			});
		},
		goGoodsCon(item) {
			this.$yrouter.push({
				path: '/pages/shop/GoodsCon/index',
				query: {
					id: item.id
				}
			});
		},
		goGoodsPromotion() {
			this.$yrouter.push('/pages/shop/GoodsPromotion/index');
		},
		setOpenShare: function() {
			if (this.$deviceType == 'weixin') {
				getShare().then(res => {
					var data = res.data.data;
					var configAppMessage = {
						desc: data.synopsis,
						title: data.title,
						link: location.href,
						imgUrl: data.img
					};
					openShareAll(configAppMessage);
				});
			}
		},
		startQr: function() {
			uni.scanCode({
				success: res => {
					let option = handleUrlParam(res.result);
					switch (option.pageType) {
						case 'good':
							// 跳转商品详情熟是嘶
							this.$yrouter.push({
								path: '/pages/shop/GoodsCon/index',
								query: {
									q: res.result
								}
							});
							break;
						case 'group':
							// 跳转团购
							this.$yrouter.push({
								path: '/pages/activity/GroupRule/index',
								query: {
									q: res.result
								}
							});
							break;
						case 'dargain':
							// 跳转砍价
							this.$yrouter.push({
								path: '/pages/activity/DargainDetails/index',
								query: {
									q: res.result
								}
							});
							break;
						default:
							// 跳转分销
							this.$yrouter.push({
								path: '/pages/Loading/index',
								query: {}
							});
							break;
					}
				}
			});
		},
		getbgcolor(e) {
			this.bgcolor = e;
		},
		dialogConfirm() {
			uni.navigateTo({
				url: '/pages/Certification/Certification'
			});
		},
		dialogClose() {
			this.$refs.popup.close();
		}
	},
	created: async function() {
		// await this.doColorThief();
	}
};
</script>
<style scoped lang="less">
// .content_box {
// 	background: #ffffff;
// }

// .index {
// 	background-color: #ffffff;
// }
.uni-indexCard {
        height: 110px;
        border-bottom: 1px #ffffff solid;
}
.uni-card .uni-card__header .uni-card__header-content .uni-card__header-content-title {
    font-size: 21px;
    color: #3a3a3a;
}
.uni-card .uni-card__header {
    display: flex;
	height: 110px;
    flex-direction: row;
    align-items: center;
    padding: 10px;
    overflow: hidden;
}
.swiper-item {
	height: 100%;
}

.fixed-header {
	position: fixed;
	z-index: 99;
	// #ifdef H5
	// #endif

	// #ifndef H5
	top: 0;
	// #endif
	left: 0;
	right: 0;
	// background: #fff;
	background: #ffffff;
	box-shadow: 0 0 20rpx -10rpx #aaa;

	& + .fixed-header-box {
		height: 98rpx;
	}
}

.head_box {
	width: 750rpx;
	// background: #fff;
	background: #ffffff;
	transition: all linear 0.3s;

	/deep/.cuIcon-back {
		display: none;
	}

	.nav-title {
		font-size: 38rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #fff;
	}
}

.cu-bar.fixed {
	position: fixed;
	width: 100%;
	top: 0;
	z-index: 1024;
	// box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
}

.cu-bar {
	box-sizing: border-box;

	.index .header {
		height: 64rpx;
		// width: 100%;
		// padding: 0 30rpx;
		// box-sizing: border-box;
	}
}

.header-search {
	transition: all linear 0.3s;
}

.cu-bar .action {
	display: -webkit-box;
	display: -webkit-flex;
	display: flex;
	align-items: center;
	height: 100%;
	max-height: 100%;

	&:first-child {
		margin-left: 15px;
		font-size: 15px;
	}
}

.home_content_box {
	margin-top: -24rpx;
}

.head_box {
}

.nav-title {
	margin-left: 20rpx;
	line-height: 40px;
}

.menu-category-box[data-v-603eefba],
.menu-swiper-box[data-v-603eefba] {
	position: relative;
	background: #ffffff;
}

.group-goods[data-v-334541a1] {
	background: #ffffff;
	border-radius: 10px;
	overflow: hidden;
}

.y-f {
	background: #ffffff;
}
.festival {
	width: 95%;
	margin: -24rpx auto;
	display: flex;
	justify-content: space-between;
	margin-bottom: 24rpx;
}
.festival-q {
	width: 350rpx;
	height: 208rpx;
}
.festival-q image {
	width: 100%;
	height: 100%;
}
.festival-w {
	position: absolute;
	width: 168rpx;
	height: 76rpx;
	margin-top: -100px;
	margin-left: 24rpx;
}
.festival-w image {
	width: 100%;
	height: 100%;
}

.bans-title {
	width: 90px;
		height: 26px;
	text-align: center;
	margin-left: 24rpx;
	margin-top: 26rpx;
	color: #fff;
	background-image: url('../../static/img/login.png');
	background-size: 100% 100%;
}
// .bans-title image{
// 	width: 152rpx;
// 	height: 46rpx;
// 	margin-top: 16rpx;
// }
.BanContain {
	position: fixed;
	width: 100%;
	top: 0;
	z-index: 1000;
}
.back-img {
	width: 34px;
	height: 34px;
	margin-left: 18rpx;
}
.navBar {
	display: flex;
	// align-items: center;
	/* padding-bottom: 10rpx; */
	background-color: #fff;
}
.status_bar {
	height: var(--status-bar-height);
	width: 100%;
	background-color: #fff;
}
</style>
